package com.zmj.service;

import com.zmj.common.api.service.CommunionService;
import com.zmj.common.model.User;
import com.zmj.common.response.ServerResponse;
import com.zmj.dubbo.proxy.RPCClientProxy;
import com.zmj.dubbo.registry.IServiceDiscovery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author zhangmj
 * @date 2019/4/3 11:25
 */
@Slf4j
@Service
public class RpcTestService {

    @Autowired
    IServiceDiscovery iServiceDiscovery;


    public ServerResponse<String> hello(String name) {
        log.info("客户端接收到打招呼的人员名称:{}",name);
        RPCClientProxy rpcClientProxy = new RPCClientProxy(iServiceDiscovery);
        CommunionService communionService = rpcClientProxy.create(CommunionService.class);
        ServerResponse<String> response = communionService.hello(name);
        log.info("RPC 客户端接收到 服务端返回打招呼用语:{}", response.getData());
        return response;
    }

    public ServerResponse<User> getInfo(Integer code) {
        log.info("客户端接收到获取人员信息编码:{}",code);
        RPCClientProxy rpcClientProxy = new RPCClientProxy(iServiceDiscovery);
        CommunionService communionService = rpcClientProxy.create(CommunionService.class);
        ServerResponse<User> response = communionService.getInfo(code);
        log.info("RPC 客户端接收到 服务端返回人员信息:{}", response.getData());
        return response;

    }
}
